package BeenChina.PM.Action;
import java.util.ArrayList;
import java.util.List;  

import BeenChina.PM.Model.ModelUser;
import BeenChina.PM.Model.ModelUserRole;
import BeenChina.PM.Service.ServiceFactory;
import BeenChina.PM.Util.JqGridBaseAction; 

public class UserInfoQueryAction extends JqGridBaseAction<ModelUser> {	
	
private static final long serialVersionUID = 1L;
 
private List<ModelUser> users = new ArrayList<ModelUser>(); 

 @Override
 public String execute() { 
	 return "load";
 }
 
 @Override
 protected List<ModelUser> listResults(int from, int length) throws Exception { 
	 try
	 { 
		 users = ServiceFactory.getInstance().getSystemInfoService().selectUsers();
		 
		 if (users!=null)
		 {
			 for (ModelUser modelUser : users) {
				
				List<ModelUserRole> userRoles = getUserRoles(modelUser.getUserID());
				if (userRoles!=null)
				{
					modelUser.setRoles(userRoles); 
				}
			 }
		 }
		 return users;
	 }
	 catch(Exception exp)
	 {
		 throw exp;
	 }
 }

@Override
public int getResultSize() {
	return this.users.size();
}

private List<ModelUserRole> getUserRoles(String userID)
{
	return ServiceFactory.getInstance().getSystemInfoService().selectUserRoles(userID);
}

}


